package com.itheima.controller;

import com.itheima.domain.Patient;
import com.itheima.service.PatientList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/patient")
public class patientController {


    @Autowired
    private PatientList patientList;


    //保存挂号信息的方法
    @RequestMapping("/save")
    public String save(Patient patient){
        //保存挂号信息进入病人数据库
        patientList.save(patient);
        return "redirect:/pages/subscribe-form.jsp";

    }


    //展示病人信息的方法 一对一查询 + 模糊查询
    @RequestMapping("/list")
    public ModelAndView findAll(Patient patient){
        ModelAndView modelAndView = new ModelAndView();
        //查询所有病人集合
        List<Patient> all = patientList.findAll(patient);
        modelAndView.addObject("list",all);
        modelAndView.setViewName("forward:/pages/patients-list.jsp");
        return modelAndView;

    }


}
